<div class="wrap">
	<ul class="order_list">
		<li>
			<label>公司名称</label>
			<select id="company"></select>
		</li>
		<li>
			<label>联系人员</label>
			<input type="text" id="userMan">
		</li>
		<li>
			<label>联系电话</label>
			<input type="text" id="userTel">
		</li>
		<li>
			<label>收货地址</label>
			<input type="text" id="userLoca">
		</li>
		<li>
			<label>产品名称</label>
			<input type="text" id="productName">
		</li>
		<li>
			<label id="changeNum" data-value="N0">产品数量</label>
			<input type="text" id="productNum">
		</li>
		<li>
			<label id="changeSpec" data-value="S0">产品规格</label>
			<select id="productSpec">
				<option value="0">210*290</option>
				<option value="1">210*145</option>
				<option value="2">260*190</option>
				<option value="3">130*190</option>
			</select>
		</li>
		<li>
			<label id="changeDemand" data-value="G0">工艺要求</label>
			<select id="productDemand">
				<option value="0">无</option>
				<option value="1">覆膜</option>
				<option value="2">UV上光</option>
				<option value="3">胶装</option>
				<option value="4">骑马钉</option>
				<option value="5">压凸</option>
				<option value="6">压型</option>
				<option value="7">裱糊</option>
				<option value="8">烫金</option>
				<option value="9">烫银</option>
			</select>
		</li>
		<li>
			<label>交货日期</label>
			<input placeholder="请输入日期" id="date" class="laydate-icon" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
		</li>
		<li>
			<label>订单总价</label>
			<input type="text" id="orderTotal" readonly="readonly">
		</li>
		<li>
			<label>付款方式</label>
			<select id="payWay">
				<option>定金70%尾款30%</option>
				<option>全款</option>
			</select>
		</li>
		<li>
			<label>备注信息</label>
			<textarea id="remark"></textarea>
		</li>
		<li>
			<a href="javascript:void(0)" id="orderSubmit">提交</a>
		</li>
	</ul>
</div>
<script>	
	//公司名称
	$.ajax({
		type:"post",
		url:"http://39.108.164.20/device/SysUser/SelClient",
		dataType:"json",
		success:function(res){
			$("#company").empty();
			var data = res.result.data;
			var html = '<option value="0">请选择公司名称</option>';
			for(let i=0;i<data.length;i++){
			   html +='<option value="'+data[i].kh_id+'">'+data[i].kh_name +'</option>';
			}
			$("#company").append(html);
		}
	});
	//公司名称下拉框选择
	$("#company").on("change",function(){
		var dataId = $(this).val();
			if(dataId>0){
				$.ajax({
				type:"post",
				url:"http://39.108.164.20/device/SysUser/SelClient",
				dataType:"json",
				success:function(res){
					var data = res.result.data;
					for(let i=0;i<data.length;i++){
						if(dataId == data[i].kh_id){
							$("#userMan").val(data[i].kh_conperson);
							$("#userTel").val(data[i].kh_tel);
							$("#userLoca").val(data[i].kh_address);
						}
					}
				}
			});
			}else{
				$("#userMan").val("请选择公司名称");
				$("#userTel").val("请选择公司名称");
				$("#userLoca").val("请选择公司名称");
			}
	})
	//数量
	var firstNum;
	var secondNum;
	var thirdNum;
	var str;
	var total;
	$("#productNum").on("blur",function(){
		if($(this).val()>50){
			firstNum = "N1";
		}else{
			firstNum = "N0";
		};
		$("#changeNum").attr("data-value",firstNum);
		secondNum  = $("#changeSpec").attr("data-value");
		thirdNum = $("#changeDemand").attr("data-value");
		str = firstNum + secondNum + thirdNum;
		$.ajax({
			type:"post",
			url:"http://39.108.164.20/device/SysUser/SelPrice",//
			dataType:"json",
			data:{
				model:str
			},
			success:function(res){
				var price = res.result.data.price;
				var num = $("#productNum").val();
				//总价
				total = price*num;
				$("#orderTotal").val(total)
			}
		})
	})
	//型号
	$("#productSpec").on("change",function(){
		secondNum = "S"+$(this).val();
		$("#changeSpec").attr("data-value",secondNum);
		firstNum = $("#changeNum").attr("data-value");
		thirdNum = $("#changeDemand").attr("data-value");
		str = firstNum + secondNum + thirdNum;
		$.ajax({
			type:"post",
			url:"http://39.108.164.20/device/SysUser/SelPrice",//
			dataType:"json",
			data:{
				model:str
			},
			success:function(res){
				var price = res.result.data.price;
				var num = $("#productNum").val();
				//总价
				total = price*num;
				$("#orderTotal").val(total)
			}
		})
	})
	//工艺
	$("#productDemand").on("change",function(){
		thirdNum = "G"+$(this).val();
		$("#changeDemand").attr("data-value",thirdNum);
		firstNum = $("#changeNum").attr("data-value");
		secondNum = $("#changeSpec").attr("data-value");
		str = firstNum + secondNum + thirdNum;
		$.ajax({
			type:"post",
			url:"http://39.108.164.20/device/SysUser/SelPrice",//
			dataType:"json",
			data:{
				model:str
			},
			success:function(res){
				var price = res.result.data.price;
				var num = $("#productNum").val();
				//总价
				total = price*num;
				$("#orderTotal").val(total)
			}
		})
	})
	//提交订单
	$("#orderSubmit").on("click",function(){
		var timestamp  = Date.parse(new Date()),
			cp_name    = $("#productName").val(),
			cp_size	   = $("#productSpec option:selected").text(),
			cp_num     = $("#productNum").val(),
			cp_craft   = $("#productDemand option:selected").text(),
			cp_total   = $("#orderTotal").val(),
			kh_id      = $("#company").val(),
			order_deadline = $("#date").val(),
			order_person = $.cookie("uid"),
			order_payway = $("#payWay").val(),
			order_comment = $("#remark").val();
		$.ajax({
			type:"post",
			url:"http://39.108.164.20/device/SysUser/InsOrder",
			dataType:"json",
			data:{
				order_id:timestamp,
				cp_name:cp_name,
				cp_size:cp_size,
				cp_num:cp_num,
				cp_craft:cp_craft,
				cp_total:cp_total,
				kh_id:kh_id,
				order_deadline:order_deadline,
				order_person:order_person,
				order_payway:order_payway,
				order_comment:order_comment
			},
			success:function(res){
				alert(res.result.msg)
			}
		});
	})
</script>